use strict;

my %vars = ();

while (<>)
{
    if (my ($v, $t, $i, $x) = /\(= \(([smn]) (\d+) (\d+)\) (\d+)\)/)
    {
        $vars{$v}->[$t]->[$i] = $x;
    }
    else
    {
        print;
    }
}

for my $v (keys %vars)
{
    print "---- [ $v ] ----\n";
    for (my $t = 0; defined ($vars{$v}->[$t][0]); ++$t)
    {
        print "$t: ";
        for (my $i = 0; defined ($vars{$v}->[$t][$i]); ++$i)
        {
            printf "%3d", $vars{$v}->[$t][$i];
        }
        print "\n";
    }
    print "\n";
}
